package com.cmc.cloud.cmclink.doc.controller.admin.special;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.constants.errorconstant.SpecialCargoRejectReasonErrorCodeConstants;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoRejectReasonConvert;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoRejectReasonDO;
import com.cmc.cloud.cmclink.doc.service.SpecialCargoRejectReasonService;
import com.cmc.cloud.cmclink.doc.vo.special.rejectreasonvo.SpecialCargoRejectReasonCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.rejectreasonvo.SpecialCargoRejectReasonPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.rejectreasonvo.SpecialCargoRejectReasonRespVO;
import com.cmc.cloud.cmclink.doc.vo.special.rejectreasonvo.SpecialCargoRejectReasonUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.exception.util.ServiceExceptionUtil;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 特种货审批长常用拒绝理由前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 特种货审批长常用拒绝理由")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/special/reject-reason")
public class SpecialCargoRejectReasonController {

    @Resource
    private SpecialCargoRejectReasonService specialCargoRejectReasonService;

    @Operation(summary = "创建特种货审批长常用拒绝理由")
    @PostMapping("/create")
    public CommonResult<Void>
        createSpecialCargoRejectReason(@Valid @RequestBody SpecialCargoRejectReasonCreateReqVO createReqVO) {
        specialCargoRejectReasonService.createSpecialCargoRejectReason(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新特种货审批长常用拒绝理由")
    @PostMapping("/update")
    public CommonResult<Void>
        updateSpecialCargoRejectReason(@Valid @RequestBody SpecialCargoRejectReasonUpdateReqVO updateReqVO) {
        specialCargoRejectReasonService.updateSpecialCargoRejectReason(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货审批长常用拒绝理由")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteSpecialCargoRejectReason(@PathVariable("id") Long id) {
        specialCargoRejectReasonService.deleteSpecialCargoRejectReason(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货审批长常用拒绝理由")
    @GetMapping("/get/detail/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @UseResponsePropertyAdvice
    public CommonResult<SpecialCargoRejectReasonRespVO> getSpecialCargoRejectReason(@PathVariable("id") Long id) {
        SpecialCargoRejectReasonDO specialCargoRejectReason =
            specialCargoRejectReasonService.getSpecialCargoRejectReason(id);
        if (specialCargoRejectReason == null) {
            throw ServiceExceptionUtil.exception(SpecialCargoRejectReasonErrorCodeConstants.REJECT_REASON_NOT_EXIST);
        }
        return CommonResult.success(SpecialCargoRejectReasonConvert.INSTANCE.convert(specialCargoRejectReason));
    }

    @Operation(summary = "获得特种货审批长常用拒绝理由分页")
    @PostMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<SpecialCargoRejectReasonRespVO>>
        getSpecialCargoRejectReasonPage(@Valid @RequestBody SpecialCargoRejectReasonPageReqVO pageVO) {
        PageResult<SpecialCargoRejectReasonDO> pageResult =
            specialCargoRejectReasonService.getSpecialCargoRejectReasonPage(pageVO);
        List<SpecialCargoRejectReasonRespVO> results =
            SpecialCargoRejectReasonConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
